$().ready(function () {
    validateRule();
    $(document).ready(function () {//通用方法去输入框去除空格
        $("form").on("change", function () {
            $("form input[type=text]").each(function () {
                this.value = this.value.replace(/\s+/g, '');
            });
        })
    });
});

$.validator.setDefaults({
    submitHandler: function () {
        update();
    }
});

function update() {
    $.ajax({
        cache: true,
        type: "POST",
        url: "/market/channelProfit/update",
        data: $('#signupForm').serialize(),// 你的formid
        async: false,
        error: function (request) {
            parent.layer.alert("Connection error");
        },
        success: function (data) {
            if (data.code == 0) {
                parent.layer.msg("操作成功");
                parent.reLoad();
                var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                parent.layer.close(index);

            } else {
                parent.layer.alert(data.msg)
            }

        }
    });
   /* $.ajax({
        url: "/market/channelProfit/channelProfitJudgingUniqueAdd",
        type: "post",
        data: $('#signupForm').serialize(),
        success: function (r) {
            if (r.code == 0) {
                $.ajax({
                    cache: true,
                    type: "POST",
                    url: "/market/channelProfit/update",
                    data: $('#signupForm').serialize(),// 你的formid
                    async: false,
                    error: function (request) {
                        parent.layer.alert("Connection error");
                    },
                    success: function (data) {
                        if (data.code == 0) {
                            parent.layer.msg("操作成功");
                            parent.reLoad();
                            var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                            parent.layer.close(index);

                        } else {
                            parent.layer.alert(data.msg)
                        }

                    }
                });
            } else {
                layer.alert("广告联盟名称重复!");
            }
        }
    });*/



}

function validateRule() {
    var icon = "<i class='fa fa-times-circle'></i> ";
    $("#signupForm").validate({
        rules: {
            channelid: {
                required: true
            },
            sdkid: {
                required: true
            }, channeldau: {
                required: true
            }, channelprofit: {
                required: true
            }, channelid: {
                required: true
            },
        },
        messages: {
            channelid: {
                required: icon + "请选择渠道"
            }, sdkid: {
                required: icon + "请选择SDK"
            }, channeldau: {
                required: icon + "请输入用户数量"
            }, channelprofit: {
                required: icon + "请选择收入"
            }
        }
    })
}